package com.ls.fw.data.hbase.client.base;

import java.io.IOException;
import java.util.List;
import java.util.NavigableMap;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;

import com.ls.fw.data.hbase.client.exception.HbaseException;

public interface BaseHbaseDao {
	
	/**
	 * 
	 * @author ls 2013-11-7 上午10:17:55
	 * @param clientPort
	 * @param quorum
	 * @param master
	 * @throws MyException
	 */
	public void changeConfig(String clientPort,String quorum,String master);
	
	/**
	 * 
	 * @author ls 2013-11-7 上午10:18:01
	 * @param master
	 * @throws MyException
	 */
	public void changeMaster(String master);
	
	/**
	 * 
	 * @author ls 2013-11-7 上午10:18:04
	 * @param quorum
	 * @throws MyException
	 */
	public void changeQuorum(String quorum);
	
	/**
	 * 
	 * @author ls 2013-11-7 上午10:18:07
	 * @param clientPort
	 * @throws MyException
	 */
	public void changeClientPort(String clientPort);
	

	public void open() throws IOException;
	
	public void close();
	
	public Configuration getConf() throws IOException ;
	
    public HConnection getConnection() throws IOException ;
    
    public HConnection getNewConnection() throws IOException ;
    
	public HConnection creatConnection(Configuration conf ) throws IOException;
    
	public HBaseAdmin creatHBaseAdmin() throws IOException ;
	
	
	public HTableInterface getTable(String tableName) throws IOException;
	
    /**
	 *  创建表操作
     * column familys add column <--->hbase columnName
     * @param tableName
     * @param familys
     * @throws Exception
	 */
	public  void createTable(String tablename, String[] familys) throws HbaseException ;

	
	/**
	 * 删除表操作
	 * 
	 * @param tablename
	 * @throws ZooKeeperConnectionException 
	 * @throws MasterNotRunningException 
	 * @throws IOException
	 */
	public  void deleteTable(String tablename) throws HbaseException;

	
	/**
	 * 删除一行记录
	 * 
	 * @param tablename
	 * @param rowkey
	 * @throws IOException
	 */
	public  void deleteRow(String tablename, String rowkey) throws HbaseException ;
	
	
	/**
	 * 删除一行记录
	 * @param table
	 * @param rowkey
	 * @throws IOException
	 */
	public  void deleteRow(HTableInterface  table, String rowkey) throws HbaseException;

	
	/**
	 * 查找一行记录
	 * 
	 * @param tablename
	 * @param rowkey
	 */
	public  Result selectRow(String tablename, String rowKey)throws HbaseException ;
	
	
	/**
	 * 查找一行记录
	 * 
	 * @param table
	 * @param rowkey
	 */
	public  Result selectRow(HTableInterface  table, String rowKey)throws HbaseException;
   
	
	/**
	 * 查找一行记录
	 * 
	 * @param table
	 * @param rowkey
	 */
	public  Result selectRow(HTableInterface  table, Get get)throws HbaseException;
	
	
	/**
     * @param tableName
     * @param rowKey
     * @param family
     * @param qualifier
     * @param value
     * @throws Exception
     */
    public  void putData(String tableName,String rowKey, String family,   String qualifier, String value) throws HbaseException ;
    
    
    
    public  void putData(HTableInterface  ht,String rowKey, String family, String qualifier, String value) throws HbaseException ;
    
    
    
    public  void putData(String tableName,String rowKey, String family, String qualifier, String value,Long version) throws HbaseException ;
    
    
    
    /**
     * 说明：
     *     一个 {row, column, version} 元组是HBase中的一个单元(cell).
     *     但是有可能会有很多的单元的行和列是相同的，可以使用版本来区分不同的单元
     * @param ht
     * @param rowKey
     * @param family
     * @param qualifier
     * @param value
     * @param version
     * @throws Exception
     */
    public  void putData(HTableInterface  ht,String rowKey, String family,String qualifier, String value,Long version) throws HbaseException ;
    
    
    public  void putData(HTableInterface  ht,KeyValue keyValue) throws HbaseException ;
    
	
	public  void putData(String tableName,KeyValue keyValue) throws HbaseException ;
    
    /**
	 * 查询符合条件的行
	 * @param tablename
	 * @param scan
	 * @return <rowkey,KeyValue[]>
     * @throws IOException 
	 */
	public NavigableMap<byte[], Cell[]> find(String tableName,Scan scan) throws HbaseException;
	
	
	
	/**
	 * 查询符合条件的行
	 * @param htable
	 * @param scan
	 * @return
	 * @throws IOException 
	 */
	public NavigableMap<byte[], Cell[]> find(HTableInterface  htable,Scan scan) throws HbaseException;
	
	
	/**
	 * 查询符合条件的结果
	 * @param tableName
	 * @param scan
	 * @return
	 * @throws IOException 
	 */
	public List<Result> findResult(String tableName,Scan scan) throws HbaseException;
	
	
	
	/**
	 * 查询符合条件的结果
	 * @param htable
	 * @param scan
	 * @return
	 * @throws IOException 
	 */
	public List<Result> findResult( HTableInterface  htable ,Scan scan) throws HbaseException;
     
	
	
	
	   /**
     * 添加列
     * @param tableName
     * @param column
     * @throws IOException
     */
    public void addColumn(String tableName, HColumnDescriptor column) throws HbaseException;
    
    
    /**
     * 修改列
     * @param tableName
     * @param column
     * @throws IOException
     */
    public void modifyColumn(String tableName, HColumnDescriptor column) throws HbaseException;
    
    public int getRowCount(String tableName) throws HbaseException;
    
    public int getRowCount(String tableName,Scan scan) throws HbaseException;
    
    
}
